// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using NUnit.Framework;
using SoapTrace.Core.Formatters;
using System;

namespace SoapTrace.Tests.Utils
{
	/// <summary>
	/// Test utility that provides test routines for the web service tests.
	/// </summary>
	public class WebServiceTestUtility
	{
		/// <summary>
		/// Private constructor since this is a utility class
		/// with static methods.
		/// </summary>
		private WebServiceTestUtility( )
		{
		}
		
		/// <summary>
		/// Compares the return values of two web service operations.
		/// </summary>
		/// <param name="expectedOperation">The expected web service operation.</param>
		/// <param name="operation">The actual web service operation.</param>
		public static void CompareReturnValue( WebServiceOperation expectedOperation, 
			WebServiceOperation operation )
		{
			CompareReturnValue( expectedOperation, operation, "" );
		}
		
		/// <summary>
		/// Compares the return values of two web service operations.
		/// </summary>
		/// <param name="expectedOperation">The expected web service operation.</param>
		/// <param name="operation">The actual web service operation.</param>
		/// <param name="message">The error message to be displayed.</param>
		public static void CompareReturnValue( WebServiceOperation expectedOperation, 
			WebServiceOperation operation,
			string message )
		{
			WebServiceReturnValue ReturnValue = operation.ReturnValue;

			WebServiceReturnValue ExpectedReturnValue = expectedOperation.ReturnValue;

			Assert.AreEqual( ExpectedReturnValue.Name, ReturnValue.Name, message );
			Assert.AreEqual( ExpectedReturnValue.Display, ReturnValue.Display, message );
			Assert.AreEqual( ExpectedReturnValue.ParameterType, ReturnValue.ParameterType, message );
			Assert.AreEqual( ExpectedReturnValue.ArrayType, ReturnValue.ArrayType, message );
			Assert.AreEqual( ExpectedReturnValue.IsArray, ReturnValue.IsArray, message );
		}
		
		/// <summary>
		/// Compares the parameters of two web service operations.
		/// </summary>
		/// <param name="expectedOperation">The expected web service operation.</param>
		/// <param name="operation">The actual web service operation.</param>
		public static void CompareParameters( WebServiceOperation expectedOperation, 
			WebServiceOperation operation )
		{
			CompareParameters( expectedOperation, operation, "" );
		}
		
		/// <summary>
		/// Compares the parameters of two web service operations.
		/// </summary>
		/// <param name="expectedOperation">The expected web service operation.</param>
		/// <param name="operation">The actual web service operation.</param>
		/// <param name="message">The error message to be displayed.</param>
		public static void CompareParameters( WebServiceOperation expectedOperation, 
			WebServiceOperation operation,
			string message )
		{
			for( int i = 0; i < operation.Parameters.Count; ++i )
			{
				WebServiceParameter Parameter = operation.Parameters[ i ];

				WebServiceParameter ExpectedParameter = expectedOperation.Parameters[ i ];

				Assert.AreEqual( ExpectedParameter.Name, Parameter.Name, message );
				Assert.AreEqual( ExpectedParameter.Display, Parameter.Display, message );
				Assert.AreEqual( ExpectedParameter.ParameterType, Parameter.ParameterType, message );
			}
		}
	}
}
